<template>
  <div>
    <span style="margin-right: 4px" v-if="textVisible">{{ leftText }}</span>
    <a-switch @change="onChange" v-model="innerValue" :checked-children="checked" :un-checked-children="unChecked" />
    <span style="margin-left: 4px">{{ rightText }}</span>
  </div>
</template>
<script>
export default {
  props: {
    value: [Number],
    checked: {
      type: String,
      required: false
    },
    unChecked: {
      type: String,
      required: false
    },
    leftText: {
      type: String,
      required: false
    },
    rightText: {
      type: String,
      required: false
    },
    textVisible: {
      type: Boolean,
      required: false,
      default: false
    }
  },
  watch: {
    value(newVal) {
      console.log(newVal)
      this.innerValue = newVal == 1 ? true : false
    }
  },
  data() {
    return {
      innerValue: false,
      newValue: false
    }
  },
  methods: {
    onChange() {
      this.$emit('input', this.innerValue ? 1 : 0)
    }
  }
}
</script>
